package com.lqk.facade.factory.simplefactory.pizzastore.order;

import com.lqk.facade.factory.simplefactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author lqk
 * @date 2021/11/30 17:06
 */
public class OrderPizza {
    // 构造器
//    public OrderPizza(){
//        Pizza pizza = null;
//        String orderType;   // 订购类型
//        do{
//            orderType = getType();
//            if ("greek".equals(orderType)){
//                pizza = new GreekPizza();
//                pizza.setName("希腊风味披萨");
//            }else if ("cheese".equals(orderType)){
//                pizza = new CheesePizza();
//                pizza.setName("奶酪披萨");
//            }else if ("pepper".equals(orderType)){
//                pizza = new CheesePizza();
//                pizza.setName("胡椒披萨");
//            } else {
//                break;
//            }
//            // 输出 pizza 制作过程
//            pizza.prepare();
//            pizza.bake();
//            pizza.cut();
//            pizza.box();
//        }while (true);
//    }

    // 定义一个简单工厂对象
    SimpleFactory simpleFactory;
    Pizza pizza = null;
    // 构造器
    public OrderPizza(SimpleFactory simpleFactory){
        setSimpleFactory(simpleFactory);
    }
    public void setSimpleFactory(SimpleFactory simpleFactory){
        String orderType = ""; // 用户输入

        this.simpleFactory = simpleFactory; // 设置简单工厂对象

        do {
            orderType = getType();
            Pizza pizza = simpleFactory.createPizza(orderType);
            if (pizza != null){
                // 输出 pizza 制作过程
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购披萨失败");
                break;
            }
        }while (true);
    }

    // 写一个方法，可以动态的获取客户希望订购的pizza种类
    private String getType(){
        try{
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        }catch (IOException e){
            e.printStackTrace();
            return "";
        }
    }
}
